/*
 * Copyright (c) 2024 iSOFT INFRASTRUCTURE SOFTWARE CO., LTD.
 * easyAda is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#include <core/addrspace.h>
#include <caps/addrspace.h>
#include <caps/capability.h>

static inline void cap_addrspace_set_obj(capability_t *cap, addrspace_t *as)
{
    cap_set_long_info(cap, (unsigned long)as);
}

void cap_addrspace_init(capability_t *cap, addrspace_t *as)
{
    (void)addrspace_get(as);
    cap_basic_init(cap, CAP_ADDRSPACE);
    cap_addrspace_set_obj(cap, as);
}

int cap_addrspce_map(capability_t *cap, unsigned long begin, unsigned int size)
{
    addrspace_t *as = cap_addrspace_get_obj(cap);

    return addrspace_map(as, begin, begin, size, 0);
}
